-- LoadingScreen
-- 载入界面
LoadingScreen = class()

function LoadingScreen:init(readMode)
    self.readMode = readMode
    self.delayed = false
    self.processBar = ProcessBar(WIDTH / 2,HEIGHT / 2 - 5,300,6)
    self.processBar.color = color(0, 255, 69, 255)
    self.processBar.backColor = color(255, 255, 255, 66)
    GameState = Loading
end

function LoadingScreen:draw()
    
    background(39, 39, 39, 255)
    

    textMode(CENTER)
    fontSize(25)
    fill(190, 190, 190, 255)
    
    if not game.created then
        text(LP.CreatingMap,WIDTH / 2,HEIGHT / 2 + 20)
        if self.delayed then
            if self.readMode then
                game:readGame()
            else
                game:createNewGame()
            end
        else
            self.delayed = true
        end
    else
        local p = chunkUpdated / (worldRenderer.chunksLength * worldRenderer.chunksHeight * worldRenderer.chunksLength)
        self.processBar.percentage = p * 0.95 + 0.05
        text(LP.RenderingChunk,WIDTH / 2,HEIGHT / 2 + 20)
        if p >= 1 or worldRenderer:getRebuildCount() == 0 then
            --[[
            if TCMode ~= ReleaseMode then
                displayMode(FULLSCREEN)
            end
              ]]
            GameState = Gaming
        end
    end
    self.processBar:draw()
end

function LoadingScreen:touched(touch)
    
end
